*"Audience Costs in the Eyes of an Adversary"
*Using Stata 16.1

**Set the directory
clear
cd

**Start a log file
log using RAP_Pilot_Korea_log, replace

**Open the data
import delimited RAP_Pilot_Korea

**Treatment
gen treatment=.
replace treatment=0 if sa!=""
replace treatment=1 if q32!=""
tab treatment
label define treatment 0 "Stay Out" 1 "Back Down"
label values treatment treatment
tab treatment

**Manipulation Checks
g manipulation=0
replace manipulation=1 if treatment==0 & threat_mc=="No" & military_action_mc=="No"
replace manipulation=1 if treatment==1 & threat_mc=="Yes" & military_action_mc=="No"
tab manipulation treatment, chi column

**Threat?
tab threat_mc
gen threat=.
replace threat=0 if threat_mc=="No"
replace threat=1 if threat_mc=="Yes"

gen military_action=.
replace military_action=0 if military_action_mc=="No"
replace military_action=1 if military_action_mc=="Yes"

tab threat treatment, column
tab military_action treatment, column

**Dependent Variable(Situational, Continuous)
tab sa
tab q32
tab ifapprove_sa
tab if_diapprove_s
gen approval_sa_7=.
replace approval_sa_7=7 if sa=="Approve" & ifapprove_sa=="Strongly"
replace approval_sa_7=6 if sa=="Approve" & ifapprove_sa=="Somewhat"
replace approval_sa_7=5 if sa=="Neither approve nor disapprove" & if_neither_sa=="Lean towards approving"
replace approval_sa_7=4 if sa=="Neither approve nor disapprove" & if_neither_sa=="Lean neither way"
replace approval_sa_7=3 if sa=="Neither approve nor disapprove" & if_neither_sa=="Lean towards disapproving"
replace approval_sa_7=2 if sa=="Disapprove" & if_diapprove_s=="Somewhat"
replace approval_sa_7=1 if sa=="Disapprove" & if_diapprove_s=="Strongly"

replace approval_sa_7=7 if q32=="Approve" & q33=="Strongly"
replace approval_sa_7=6 if q32=="Approve" & q33=="Somewhat"
replace approval_sa_7=5 if q32=="Neither approve nor disapprove" & q35=="Lean towards approving"
replace approval_sa_7=4 if q32=="Neither approve nor disapprove" & q35=="Lean neither way"
replace approval_sa_7=3 if q32=="Neither approve nor disapprove" & q35=="Lean towards disapproving"
replace approval_sa_7=2 if q32=="Disapprove" & q34=="Somewhat"
replace approval_sa_7=1 if q32=="Disapprove" & q34=="Strongly"

tab approval_sa_7

ttest approval_sa_7, by(treatment)
ttest approval_sa_7 if manipulation==1, by(treatment)

**Dependent Variable(General, Continuous)
tab ga
tab if_approve_ga
tab if_disapprove_ga
tab if_neither_ga
tab q36
tab q37 
tab q38 
tab q39
gen approval_ga_7=.
replace approval_ga_7=7 if ga=="Approve" & if_approve_ga=="Strongly"
replace approval_ga_7=6 if ga=="Approve" & if_approve_ga=="Somewhat"
replace approval_ga_7=5 if ga=="Neither approve nor disapprove" & if_neither_ga=="Lean towards approving"
replace approval_ga_7=4 if ga=="Neither approve nor disapprove" & if_neither_ga=="Lean neither way"
replace approval_ga_7=3 if ga=="Neither approve nor disapprove" & if_neither_ga=="Lean towards disapproving"
replace approval_ga_7=2 if ga=="Disapprove" & if_disapprove_ga=="Somewhat"
replace approval_ga_7=1 if ga=="Disapprove" & if_disapprove_ga=="Strongly"

replace approval_ga_7=7 if q36=="Approve" & q37=="Strongly"
replace approval_ga_7=6 if q36=="Approve" & q37=="Somewhat"
replace approval_ga_7=5 if q36=="Neither approve nor disapprove" & q39=="Lean towards approving"
replace approval_ga_7=4 if q36=="Neither approve nor disapprove" & q39=="Lean neither way"
replace approval_ga_7=3 if q36=="Neither approve nor disapprove" & q39=="Lean towards disapproving"
replace approval_ga_7=2 if q36=="Disapprove" & q38=="Somewhat"
replace approval_ga_7=1 if q36=="Disapprove" & q38=="Strongly"

tab approval_ga_7

ttest approval_ga_7, by(treatment)
ttest approval_ga_7 if manipulation==1, by(treatment)

**Dependent Variable(Situational, Dichotomous)
tab sa
tab q32
gen approval_sa_dummy=.
replace approval_sa_dummy=0 if sa!="Approve" & sa!=""
replace approval_sa_dummy=1 if sa=="Approve" & sa!=""

replace approval_sa_dummy=0 if q32!="Approve" & q32!=""
replace approval_sa_dummy=1 if q32=="Approve" & q32!=""

tab approval_sa_dummy

ttest approval_sa_dummy, by(treatment)
ttest approval_sa_dummy if manipulation==1, by(treatment)

**Dependent Variable(General, Dichotomous)
tab ga
tab q36
gen approval_ga_dummy=.
replace approval_ga_dummy=0 if ga!="Approve" & ga!=""
replace approval_ga_dummy=1 if ga=="Approve" & ga!=""

replace approval_ga_dummy=0 if q36!="Approve" & q36!=""
replace approval_ga_dummy=1 if q36=="Approve" & q36!=""

tab approval_ga_dummy

ttest approval_ga_dummy, by(treatment)
ttest approval_ga_dummy if manipulation==1, by(treatment)

**Response Time
sum durationinseconds, detail
gen inattentive=0
replace inattentive=1 if durationinseconds<102|durationinseconds>1168
tab inattentive

ttest approval_sa_7 if inattentive!=1, by(treatment)
ttest approval_ga_7 if inattentive!=1, by(treatment)
ttest approval_sa_dummy if inattentive!=1, by(treatment)
ttest approval_ga_dummy if inattentive!=1, by(treatment)

gen inattentive_2=0
replace inattentive_2=1 if durationinseconds<126|durationinseconds>759
tab inattentive_2

ttest approval_sa_7 if inattentive_2!=1, by(treatment)
ttest approval_ga_7 if inattentive_2!=1, by(treatment)
ttest approval_sa_dummy if inattentive_2!=1, by(treatment)
ttest approval_ga_dummy if inattentive_2!=1, by(treatment)

***Balance Checks
**Gender (Male=1, Not Male=0)
tab gender
gen Male=.
replace Male=1 if gender=="Male"
replace Male=0 if gender!="Male"
tab Male
ttest Male, by(treatment)

**Ideology (Strongly conservative=1, Strongly liberal=7)
tab ideology
gen ideology_7=.
replace ideology_7=1 if ideology=="Strongly conservative"
replace ideology_7=2 if ideology=="Somewhat conservative"
replace ideology_7=3 if ideology=="Slightly conservative"
replace ideology_7=4 if ideology=="Neither conservative nor liberal"
replace ideology_7=5 if ideology=="Slightly liberal"
replace ideology_7=6 if ideology=="Somewhat liberal"
replace ideology_7=7 if ideology=="Strongly liberal"
tab ideology_7
ttest ideology_7, by(treatment)

**Prior Knowledge (Strongly disinterested=1, Strongly interested=7)
tab prior_knowledge
gen prior_knowledge_7=.
replace prior_knowledge_7=1 if prior_knowledge=="Strongly disinterested"
replace prior_knowledge_7=2 if prior_knowledge=="Somewhat disinterested"
replace prior_knowledge_7=3 if prior_knowledge=="Slightly disinterested"
replace prior_knowledge_7=4 if prior_knowledge=="Neither interested nor disinterested"
replace prior_knowledge_7=5 if prior_knowledge=="Slightly interested"
replace prior_knowledge_7=6 if prior_knowledge=="Somewhat interested"
replace prior_knowledge_7=7 if prior_knowledge=="Strongly interested"
tab prior_knowledge_7
ttest prior_knowledge_7, by(treatment)

**Income (Less than 2 million won=1, >7 million won=7)
tab income
gen income_7=.
replace income_7=1 if income=="Less than 2 million won"
replace income_7=2 if income=="2-3 million won"
replace income_7=3 if income=="3-4 million won"
replace income_7=4 if income=="4-5 million won"
replace income_7=5 if income=="5-6 million won"
replace income_7=6 if income=="6-7 million won"
replace income_7=7 if income==">7 million won"
tab income_7
ttest income_7, by(treatment)

**Education (1=4-year college graduate or more, 0=Otherwise)
tab education
gen college_grad=0
replace college_grad=1 if education=="4-year college graduate"|education=="Graduate school graduate"
tab college_grad
ttest college_grad, by(treatment)

**Age (1=4-year college graduate or more, 0=Otherwise)
tab age
gen age_7=.
replace age_7=1 if age=="18-24"
replace age_7=2 if age=="25-32"
replace age_7=3 if age=="33-40"
replace age_7=4 if age=="41-48"
replace age_7=5 if age=="49-56"
replace age_7=6 if age=="57-64"
replace age_7=7 if age=="65+"
tab age_7
ttest age_7, by(treatment)

**Religion (1=Religious, 0=Not Religious)
tab religion
gen religion_1=.
replace religion_1=0 if religion=="None"
replace religion_1=1 if religion!="None"
tab religion_1
ttest religion_1, by(treatment)

**Feeling toward Japan (1=Very unfavorably, 7=Very favorably)
tab feeling_toward_japan
gen feeling_toward_japan_7=.
replace feeling_toward_japan_7=1 if feeling_toward_japan=="Very unfavorably"
replace feeling_toward_japan_7=2 if feeling_toward_japan=="Somewhat unfavorably"
replace feeling_toward_japan_7=3 if feeling_toward_japan=="Slightly unfavorably"
replace feeling_toward_japan_7=4 if feeling_toward_japan=="Neither unfavorably nor favorably"
replace feeling_toward_japan_7=5 if feeling_toward_japan=="Slightly favorably"
replace feeling_toward_japan_7=6 if feeling_toward_japan=="Somewhat favorably"
replace feeling_toward_japan_7=7 if feeling_toward_japan=="Very favorably"
tab feeling_toward_japan_7
ttest feeling_toward_japan_7, by(treatment)

**Pastrisanship (1=Democratic Party, 2=People Power Party, 3=Others)
tab partisanship
gen partisanship_3=.
replace partisanship_3=1 if partisanship=="Democratic Party"
replace partisanship_3=2 if partisanship=="People Power Party"
replace partisanship_3=3 if partisanship!="Democratic Party" & partisanship!="People Power Party" 
tab partisanship_3

**Pastrisanship (1=Democratic Party,0=Others)
gen democratic=.
replace democratic=1 if partisanship_3==1
replace democratic=0 if partisanship_3==2 | partisanship_3==3 
tab democratic
ttest democratic, by(treatment)

**Pastrisanship (1=People Power Party, 0=Others)
gen people_power=.
replace people_power=1 if partisanship_3==2
replace people_power=0 if partisanship_3==1 | partisanship_3==3
tab people_power
ttest people_power, by(treatment)

**OLS
reg approval_sa_7 treatment Male age_7 ideology_7 prior_knowledge_7 income_7 college_grad religion_1 feeling_toward_japan_7 democratic people_power
estimates store Model1

reg approval_ga_7 treatment Male age_7 ideology_7 prior_knowledge_7 income_7 college_grad religion_1 feeling_toward_japan_7 democratic people_power
estimates store Model2

reg approval_sa_dummy treatment Male age_7 ideology_7 prior_knowledge_7 income_7 college_grad religion_1 feeling_toward_japan_7 democratic people_power
estimates store Model3

reg approval_ga_dummy treatment Male age_7 ideology_7 prior_knowledge_7 income_7 college_grad religion_1 feeling_toward_japan_7 democratic people_power
estimates store Model4

esttab Model1 Model2 Model3 Model4 using ols.tex, replace se r2 legend label collabels(none) varlabels(_cons Constant) star(* 0.05 ** 0.01)

***Mechanisms
*Credibility
tab credibility
gen credibility_1=.
replace credibility_1=1 if credibility=="Yes"
replace credibility_1=0 if credibility=="No"
ttest credibility_1, by(treatment)

*Competency
tab competency
gen competency_1=.
replace competency_1=1 if competency=="Yes"
replace competency_1=0 if competency=="No"
ttest competency_1, by(treatment)

*Reputation
tab reputation
gen reputation_1=.
replace reputation_1=1 if reputation=="Yes"
replace reputation_1=0 if reputation=="No"
ttest reputation_1, by(treatment)

*Morality
tab morality
gen morality_1=.
replace morality_1=1 if credibility=="Yes"
replace morality_1=0 if credibility=="No"
ttest morality_1, by(treatment)

**Balance Check
sum treatment approval_sa_7 approval_ga_7 approval_sa_dummy approval_ga_dummy Male age_7 ideology_7 prior_knowledge_7 income_7 college_grad religion_1 feeling_toward_japan_7 democratic people_power

ttesttable Male treatment, ref(0) uneq
ttesttable age_7 treatment, ref(0) uneq
ttesttable ideology_7 treatment, ref(0) uneq
ttesttable prior_knowledge_7 treatment, ref(0) uneq
ttesttable income_7 treatment, ref(0) uneq
ttesttable college_grad treatment, ref(0) uneq
ttesttable religion_1 treatment, ref(0) uneq
ttesttable feeling_toward_japan_7 treatment, ref(0) uneq
ttesttable democratic treatment, ref(0) uneq
ttesttable people_power treatment, ref(0) uneq

**Manipulation Checks
tab treatment manipulation, row chi2
ttest approval_sa_7 if manipulation==1, by(treatment)
ttest approval_ga_7 if manipulation==1, by(treatment)
ttest approval_sa_dummy if manipulation==1, by(treatment)
ttest approval_ga_dummy if manipulation==1, by(treatment)

*Continous
reg approval_sa_7 treatment Male age_7 ideology_7 prior_knowledge_7 income_7 college_grad religion_1 feeling_toward_japan_7 democratic people_power if manipulation==1
estimates store Model1

reg approval_ga_7 treatment Male age_7 ideology_7 prior_knowledge_7 income_7 college_grad religion_1 feeling_toward_japan_7 democratic people_power if manipulation==1
estimates store Model2

reg approval_sa_dummy treatment Male age_7 ideology_7 prior_knowledge_7 income_7 college_grad religion_1 feeling_toward_japan_7 democratic people_power if manipulation==1
estimates store Model3

reg approval_ga_dummy treatment Male age_7 ideology_7 prior_knowledge_7 income_7 college_grad religion_1 feeling_toward_japan_7 democratic people_power if manipulation==1
estimates store Model4

esttab Model1 Model2 Model3 Model4 using manipulation.tex, replace se r2 legend label collabels(none) varlabels(_cons Constant) star(* 0.05 ** 0.01)

***Heterogenous Effect
**Conditional Effect of Gender?
*Situational Approval, 7 scale
regress approval_sa_7 i.treatment##i.Male

regress approval_sa_7 i.treatment if Male==0
estimates store NotMale

regress approval_sa_7 i.treatment if Male==1
estimates store Male

coefplot NotMale Male, keep(*.treatment) drop(_cons) xline(0) base title(Henerogenous Effect (Male), size(medium))
graph export "ac_male_sa_7.pdf", replace

*General Approval, 7 scale
regress approval_ga_7 i.treatment##i.Male

regress approval_ga_7 i.treatment if Male==0
estimates store NotMale

regress approval_ga_7 i.treatment if Male==1
estimates store Male

coefplot NotMale Male, keep(*.treatment) drop(_cons) xline(0) base title(Henerogenous Effect (Male), size(medium))
graph export "ac_male_ga_7.pdf", replace

*Situational Approval, Dichotomous
regress approval_sa_dummy i.treatment##i.Male

regress approval_sa_dummy i.treatment if Male==0
estimates store NotMale

regress approval_sa_dummy i.treatment if Male==1
estimates store Male

coefplot NotMale Male, keep(*.treatment) drop(_cons) xline(0) base title(Henerogenous Effect (Male), size(medium))
graph export "ac_male_sa_dummy.pdf", replace

*General Approval, Dichotomous
regress approval_ga_dummy i.treatment##i.Male

regress approval_ga_dummy i.treatment if Male==0
estimates store NotMale

regress approval_ga_dummy i.treatment if Male==1
estimates store Male

coefplot NotMale Male, keep(*.treatment) drop(_cons) xline(0) base title(Henerogenous Effect (Male), size(medium))
graph export "ac_male_ga_dummy.pdf", replace

**Conditional Effect of Age?
sum age_7, detail
gen Old=.
replace Old=1 if age_7>4
replace Old=0 if age_7<=4
tab Old

*Situational Approval, 7 scale
regress approval_sa_7 i.treatment##i.Old

regress approval_sa_7 i.treatment if Old==0
estimates store NotOld

regress approval_sa_7 i.treatment if Male==1
estimates store Old

coefplot NotOld Old, keep(*.treatment) drop(_cons) xline(0) base title(Henerogenous Effect (Age), size(medium))
graph export "ac_old_sa_7.pdf", replace

*General Approval, 7 scale
regress approval_ga_7 i.treatment##i.Old

regress approval_ga_7 i.treatment if Old==0
estimates store NotOld

regress approval_ga_7 i.treatment if Male==1
estimates store Old

coefplot NotOld Old, keep(*.treatment) drop(_cons) xline(0) base title(Henerogenous Effect (Age), size(medium))
graph export "ac_old_ga_7.pdf", replace

*Situational Approval, Dichotomous
regress approval_sa_dummy i.treatment##i.Old

regress approval_sa_dummy i.treatment if Old==0
estimates store NotOld

regress approval_sa_dummy i.treatment if Old==1
estimates store Old

coefplot NotOld Old, keep(*.treatment) drop(_cons) xline(0) base title(Henerogenous Effect (Age), size(medium))
graph export "ac_old_sa_dummy.pdf", replace

*General Approval, Dichotomous
regress approval_ga_dummy i.treatment##i.Old

regress approval_ga_dummy i.treatment if Old==0
estimates store NotOld

regress approval_ga_dummy i.treatment if Old==1
estimates store Old

coefplot NotOld Old, keep(*.treatment) drop(_cons) xline(0) base title(Henerogenous Effect (Age), size(medium))
graph export "ac_old_ga_dummy.pdf", replace

**End the log file
log close